package com.itheima.sh.user.controller;

import com.itheima.sh.pojo.User;
import com.itheima.sh.response.UserOrderVO;
import com.itheima.sh.user.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description:
 * @Version: V1.0
 */
@RestController
@RequestMapping("user")
@RefreshScope
@Api(value = "用户管理", tags = "用户", description = "用户管理API")
public class UserController {

    @Autowired
    UserService userService;

    @Autowired
    Environment environment;

    @Value("${test.name}")
    private String name;

    @GetMapping("findUserById/{username}")  // /itcast
    @ApiOperation(value = "根据用户名查询用户信息")
    public User findUserById( @PathVariable("username") @ApiParam("用户登录名") String id) {

        System.out.println("Server PORT: " +environment.getProperty("server.port"));
        System.out.println("name="+name);

        return userService.findUserById(id);
    }

    @GetMapping("findOrderByUserId/{username}")  // /itcast
    @ApiOperation(value = "根据用户名查询用户所属订单")
    public UserOrderVO findOrderByUserId(@PathVariable("username") @ApiParam("用户登录名") String id) {
        return userService.findOrderByUserId(id);
    }
}
